import React from 'react'
import ReactDOM from 'react-dom'

class FlavorForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = { value: 'mango' };
    this.handleSubmit = this.handleSubmit.bind(this);
    this.handleChange = this.handleChange.bind(this);
  }
  handleSubmit(e) {
    console.log('喜欢的水果是：' + this.state.value);
    e.preventDefault()
  }
  handleChange(e) {
    this.setState({ value: e.target.value });
  }
  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <select value={this.state.value} onChange={this.handleChange}>
          <option value="grapefruit">葡萄柚</option>
          <option value="lime">酸橙</option>
          <option value="coconut">椰子</option>
          <option value="mango">芒果</option>
        </select>
        <input type="submit" value="提交"></input>
      </form>
    )
  }
}

ReactDOM.render(
  <FlavorForm />,
  document.getElementById('root')
)